/******************************************************************************************
 * Import
 ******************************************************************************************/

// module
import React, {Component} from 'react';
import {View, Dimensions } from 'react-native';
import { Icon, Button, Modal } from 'antd-mobile-rn';

// project
import {Page, Content, Header, Between, ItemX, ItemY, Text, TouchOpacity} from '../../../../library'


/******************************************************************************************
 * Export Class
 ******************************************************************************************/

export default class UserProtocol extends Component {

    /*------------------------------------------------------------------------------------
	 * 初始化
	 *-----------------------------------------------------------------------------------*/
    constructor(props) {
        super(props);
        this.Nav = this.props.navigation;



        /**
         * state
         */
        this.state = {
            data:{},
        };
    }

    /**
     * didMount
     */
    componentDidMount(){
        // http请求
        HttpTemp.get({
            url:"/page/mycar/detail.php",
            success:(res) => {
                let data = res.data;
                this.setState({
                    data:data,
                })
            }
        })

    }


    deleteCar(){
        HttpTemp.post({

            url:"/page/mycar/logic/delete.php",
            data:{
                id:this.state.data.id
            },
            success:(res) => {
                Toast.info("删除成功", 2);
                //需要回跳
            },
            error: {
                code: (res)=> {
                    Toast.info(res.msg,2);
                }
            }

        })

    }




    /*------------------------------------------------------------------------------------
	 * 渲染
	 *-----------------------------------------------------------------------------------*/
    render(){
        var windowWidth = Dimensions.get('window').width;
        return(
            <Page>

                <Content bg='rgba(248, 248, 248, 1)' mt='48'>

                    <View>

                        {/* 车辆信息标题 */}
                        <ItemX w={windowWidth/24*22} ml={windowWidth/24*1}  h="40" y="center"> 
                            <Text color="#AEAEAE">车辆信息</Text>
                        </ItemX>

                        {/* 车辆信息 */}
                        <ItemY  w={windowWidth} bg="white">

                            {/* 车牌号码详情 */}
                            <ItemX w={windowWidth/24*22} ml={windowWidth/24*1} style={{ borderBottomWidth:1, borderBottomColor:"#eee" }}  h="50" y="center"> 
                                <Between>
                                    <Text color="#434343">车牌号码</Text>
                                    <Text color="#434343">{this.state.data.set_number}</Text>
                                </Between>
                            </ItemX>

                            {/* 车辆品牌详情 */}
                            {/* <ItemX w={windowWidth/24*22} ml={windowWidth/24*1} style={{ borderBottomWidth:1, borderBottomColor:"#eee" }}  h="50" y="center"> 
                                <Between>
                                    <Text color="#434343">车辆品牌</Text>
                                    <Text color="#434343">奔驰</Text>
                                </Between>
                            </ItemX> */}

                            {/* 车辆型号详情 */}
                            {/* <ItemX w={windowWidth/24*22} ml={windowWidth/24*1}  h="50" y="center"> 
                                <Between>
                                    <Text color="#434343">车辆型号</Text>
                                    <Text color="#434343">S200</Text>
                                </Between>
                            </ItemX>
 */}
                        </ItemY>

                        {/* 删除按钮，删除之前会询问用户是否确认删除 */}
                        <ItemY x="center" mt="20">
                            <Button onClick={()=>{
                                Modal.alert('确定要删除吗', '删除后不可恢复', [
                                    { text: '确定', onPress: () => {
                                        this.deleteCar();
                                    }, style:{ color:"#797979" }},
                                    { text: '取消', onPress: () => {}, style:{ color:"#02B349" }},
                                ]);

                            }} style={{ width:windowWidth/24*20, height:40, backgroundColor:"rgba(2, 179, 73, 1)", borderWidth:0}}>
                                <Text size="14" color="white">删除</Text>
                            </Button>
                        </ItemY>

                    </View>

                </Content>

                {/* 顶部 star */}
                <Header h='48' y='center' bg='#fff' style={{ borderBottomColor:"#eee", borderBottomWidth:1 }}>
                    <Between px='10'>
                        <TouchOpacity active={0.6} onPress={(e)=> {
                            this.Nav.goBack()
                        }}>
                            <Icon type='left' size='md' color='#00CC66' />
                        </TouchOpacity>

                        <Text size='17'>车辆详情</Text>
                        <Text> </Text>
                    </Between>
                </Header>
                {/* 顶部 star */}

            </Page>
        )
    }
}

